<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        th{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<br/>
<div style="width:600px;margin: 0 auto;">
    <form class="layui-form" name="form1" action="{:url('index/postbusiness/dosettlement')}" id="sub" method="post" enctype="multipart/form-data">
        <input type="hidden" name="sid" value="{$sid}"/>
        <input type="hidden" name="bid" value="{$bid}"/>
        <input type="hidden" name="pid" value="{$pid}"/>
        <input type="hidden" name="inventoryid" value="{$inventoryid}"/>
        <input type="hidden" name="uploadprove" id="uploadprove" />
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">产品名称</label>
            <div class="layui-input-block">
                <input type="text" name="pname" readonly value="{$result.pname}" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">单价(元)</label>
            <div class="layui-input-block">
                <input type="text" name="unitprice" readonly value="{$result.purchaseprice}" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:110px;">结算数量(个)</label>
            <div class="layui-input-block">
                <input type="text" name="number" readonly value="{$sellnumber}"  required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">总价(元)</label>
            <div class="layui-input-block">
                <input type="text" name="total" readonly value="{$total}" required  lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width:100px;">支付证明</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="upload">
                    <i class="layui-icon">&#xe67c;</i>上传支付证明
                </button>
            </div>
        </div>
        <div class="layui-form-item" id="prove" style="display: none">
            <label class="layui-form-label" style="width:100px;">支付证明</label>
            <div class="layui-input-block">
                <img src="" id="images" width="80px" height="80px"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" onclick="settlement()" class="btn btn-primary">结算</button>
                <button type="button" onclick="pushback()" class="btn btn-default">返回</button>
            </div>
        </div>
    </form>
</div>
</body>
<script>

    layui.use('form', function(){

    });
    //上传支付凭证
    layui.use('upload', function(){
        var upload = layui.upload;
        var pid = $("input[name=pid]").val();
        //执行实例
        upload.render({
            elem: '#upload' //绑定元素
            ,url: "{:url('index/postbusiness/uploadimage')}?pid="+pid //上传接口
            ,field:'uploadimage'
            ,done: function(res){
                if(res.image){
                    $("#images").attr('src',"__ROOT__\\"+res.image);
                    $("#uploadprove").val(res.image);
                    $("#prove").css('display','block');
                }
                if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    });
    //结算
    function settlement() {
        var uploadprove = $("#uploadprove").val();
        if(!uploadprove){
            layer.alert('请上传支付凭证');
            return;
        }
        $.ajax({
            url:"{:url('index/postbusiness/dosettlement')}",
            data:$("#sub").serialize(),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.success){
                    layer.alert(res.success,{bnt:['确定','取消']},function () {
                        window.history.go(-1);
                    },function () {
                        window.history.go(-1);
                    });
                }else if(res.error){
                    layer.alert(res.error);
                }
            }
        });
    }
    //返回
    function pushback() {
        window.history.go(-1);
    }
</script>
</html>